package com.xishu.entity;

import com.xishu.annotation.dao.*;
import com.xishu.annotation.oplog.OplogAnnotation;
import com.xishu.annotation.valid.UniqueName;
import com.xishu.entity.oplog.OpName;
import io.swagger.annotations.ApiModelProperty;
import net.sf.json.JSONObject;

import javax.persistence.*;
import java.util.List;

@Entity(name = "user")
@Table(indexes = {@Index(columnList = "name"), @Index(columnList = "shopId")})
public class User extends ShopItem implements OpName {
    private static final long serialVersionUID = 2486157330491498544L;


    @Transient
    private String opName;

    @Column(nullable = false)
    @OplogAnnotation(fieldName = "姓名")
    @UniqueName
    @Search(like = true)
    private String name;

    @OplogAnnotation(fieldName = "密码")
    @Search(ignore = true)
    @Hidden
    private String password;

    @Transient
    @OplogAnnotation(fieldName = "密码")
    @ApiModelProperty(value = "确认密码")
    private String confirmPassword;

    @Search(ignore = true)
    @OplogAnnotation(fieldName = "盐值")
    @Hidden
    private String salt;

    @ApiModelProperty(value = "描述")
    @Search(like = true)
    @OplogAnnotation(fieldName = "描述")
    private String description;

    @ApiModelProperty(value = "是否是admin")
    @NotModify
    private Boolean admin;

    @ApiModelProperty(value = "是否是平台管理员")
    private Boolean platManager;

    @ApiModelProperty(value = "是否是餐厅公司管理员")
    private Boolean companyManager;

    @ApiModelProperty(value = "是否是分店经理")
    private Boolean shopManager;

    @ApiModelProperty(value = "是否是服务员")
    private Boolean waiter;

    @ApiModelProperty(value = "用户状态,0是正常，1是锁定，2是未开通")
    @NotModify
    private Integer status;

    @ApiModelProperty(value = "餐厅账号绑定的餐厅")
    private Long companyId;

    @ApiModelProperty(value = "账号绑定的分店，特别为餐厅服务员查询用")
    private Long shopId;

    @ApiModelProperty(value = "账号绑定的分店列表，方便前端查询用")
    private String shopIdString;

    @ApiModelProperty(value = "用户显示的姓名")
    @Search(like = true)
    @OplogAnnotation(fieldName = "用户名称")
    private String nickName;

    @ApiModelProperty(value = "用户的图片显示")
    @OplogAnnotation(fieldName = "用户图片")
    private String imgId;

    @ApiModelProperty(value = "用户绑定的邮箱")
    @OplogAnnotation(fieldName = "用户邮箱")
    @Search(like = true)
    private String email;

    @ApiModelProperty(value = "二级密码,分店经理分有该项")
    @OplogAnnotation(fieldName = "二级密码")
    @Hidden
    private String secondaryPassword;

    @Transient
    @ApiModelProperty(value = "确认二级密码")
    private String confirmSecondaryPassword;

    @ApiModelProperty(value = "二级密码对应的盐值，分店经理分有该项")
    @Hidden
    private String secondarySalt;

    @ApiModelProperty(value = "餐厅经理的权限")
    @FieldMapping(desField = "shopPrivilegeList", serialize = false, genericType = "java.lang.String")
    @Column(length = 2048)
    @OplogAnnotation(fieldName = "餐厅经理的权限")
    private String shopPrivilegeJson;

    @Transient
    @ApiModelProperty(value = "餐厅经理的权限,只是对应权限的一个ID，具体的权限需要到映射关系里面去查询")
    @FieldMapping(desField = "shopPrivilegeJson", serialize = true)
    private List<String> shopPrivilegeList;

    @ApiModelProperty(value = "账号拥有的权限")
    @FieldMapping(desField = "privilegeList", serialize = false, genericType = "java.lang.String")
    @OplogAnnotation(fieldName = "用户的权限")
    @Lob
    @Column(columnDefinition = "MEDIUMTEXT")
    private String privilegeJson;

    @Transient
    @ApiModelProperty(value = "账号拥有的权限")
    @FieldMapping(desField = "privilegeJson", serialize = true, genericType = "java.lang.String")
    @DefaultValue(defaultValue = "")
    private List<String> privilegeList;

    @Transient
    @ApiModelProperty(value = "邀请经理注册的语言")
    private String lang;

    @Transient
    @ApiModelProperty(value = "邀请经理注册的时候使用")
    private List<Long> shopIdList;

    @ApiModelProperty(value = "在线触摸屏设备数")
    private Integer onlineTouchDeviceNumber;

    @ApiModelProperty(value = "输错密码次数")
    @NotModify
    private Integer failedTime;

    @Search(ignore = true)
    @Transient
    @NotModify
    private String token;

    @ApiModelProperty(value = "带参数查询相关联的分店")
    @Transient
    private Boolean queryShopName;

    @ApiModelProperty(value = "查询相关联的分店名")
    @Transient
    private String shopName_zh;

    @ApiModelProperty(value = "查询相关联的分店名")
    @Transient
    private String shopName_en;

    @Transient
    @ApiModelProperty(value = "餐厅名称")
    private String companyName;

    @Transient
    @ApiModelProperty(value = "添加判断，是否是B端登录的账号")
    private Boolean bEndLogin;


    public Boolean getbEndLogin() {
        return bEndLogin;
    }

    public void setbEndLogin(Boolean bEndLogin) {
        this.bEndLogin = bEndLogin;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Boolean getQueryShopName() {
        return queryShopName;
    }

    public void setQueryShopName(Boolean queryShopName) {
        this.queryShopName = queryShopName;
    }

    public String getShopName_zh() {
        return shopName_zh;
    }

    public void setShopName_zh(String shopName_zh) {
        this.shopName_zh = shopName_zh;
    }

    public String getShopName_en() {
        return shopName_en;
    }

    public void setShopName_en(String shopName_en) {
        this.shopName_en = shopName_en;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Integer getFailedTime() {
        return failedTime;
    }

    public void setFailedTime(Integer failedTime) {
        this.failedTime = failedTime;
    }

    public Integer getOnlineTouchDeviceNumber() {
        return onlineTouchDeviceNumber;
    }

    public void setOnlineTouchDeviceNumber(Integer onlineTouchDeviceNumber) {
        this.onlineTouchDeviceNumber = onlineTouchDeviceNumber;
    }

    public List<Long> getShopIdList() {
        return shopIdList;
    }

    public void setShopIdList(List<Long> shopIdList) {
        this.shopIdList = shopIdList;
    }

    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    public String getShopPrivilegeJson() {
        return shopPrivilegeJson;
    }

    public void setShopPrivilegeJson(String shopPrivilegeJson) {
        this.shopPrivilegeJson = shopPrivilegeJson;
    }

    public List<String> getShopPrivilegeList() {
        return shopPrivilegeList;
    }

    public void setShopPrivilegeList(List<String> shopPrivilegeList) {
        this.shopPrivilegeList = shopPrivilegeList;
    }

    public String getPrivilegeJson() {
        return privilegeJson;
    }

    public void setPrivilegeJson(String privilegeJson) {
        this.privilegeJson = privilegeJson;
    }

    public List<String> getPrivilegeList() {
        return privilegeList;
    }

    public void setPrivilegeList(List<String> privilegeList) {
        this.privilegeList = privilegeList;
    }

    public String getSecondaryPassword() {
        return secondaryPassword;
    }

    public void setSecondaryPassword(String secondaryPassword) {
        this.secondaryPassword = secondaryPassword;
    }

    public String getSecondarySalt() {
        return secondarySalt;
    }

    public void setSecondarySalt(String secondarySalt) {
        this.secondarySalt = secondarySalt;
    }

    public Boolean getShopManager() {
        return shopManager;
    }

    public void setShopManager(Boolean shopManager) {
        this.shopManager = shopManager;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getImgId() {
        return imgId;
    }

    public void setImgId(String imgId) {
        this.imgId = imgId;
    }

    public Boolean getAdmin() {
        return admin;
    }

    public void setAdmin(Boolean admin) {
        this.admin = admin;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getName() {
        return name;
    }

    @Override
    public String opType() {
        return "用户账号";
    }

    @Override
    public String[] fieldName() {
        return new String[]{"name"};
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return JSONObject.fromObject(this).toString();
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public Boolean getPlatManager() {
        return platManager;
    }

    public void setPlatManager(Boolean platManager) {
        this.platManager = platManager;
    }

    public Boolean getCompanyManager() {
        return companyManager;
    }

    public void setCompanyManager(Boolean companyManager) {
        this.companyManager = companyManager;
    }

    public Boolean getWaiter() {
        return waiter;
    }

    public void setWaiter(Boolean waiter) {
        this.waiter = waiter;
    }

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    @Override
    public String getOpName() {
        return opName;
    }

    @Override
    public void setOpName(String opName) {
        this.opName = opName;
    }

    public String getShopIdString() {
        return shopIdString;
    }

    public void setShopIdString(String shopIdString) {
        this.shopIdString = shopIdString;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getConfirmSecondaryPassword() {
        return confirmSecondaryPassword;
    }

    public void setConfirmSecondaryPassword(String confirmSecondaryPassword) {
        this.confirmSecondaryPassword = confirmSecondaryPassword;
    }
}
